export function downloadFile(file: Blob, fileName = '') {
  const url = URL.createObjectURL(file)
  const a = document.createElement('a')
  a.style.display = 'none'
  a.setAttribute('target', '_blank')
  a.setAttribute('download', fileName)
  a.href = url
  document.body.appendChild(a)
  a.click()
  document.body.removeChild(a)
  URL.revokeObjectURL(url)
}

export function convertStrToBuffer(str: string): ArrayBuffer {
  let buf = new ArrayBuffer(str.length * 2) // 2 bytes for each char
  let bufView = new Uint16Array(buf)
  for (let i = 0, strLen = str.length; i < strLen; i++) {
    bufView[i] = str.charCodeAt(i)
  }
  return buf
}
